<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');session_start();class Login extends CI_Controller {
	protected  $language = 0;	public function __construct()	{		parent::__construct();
		$this->load->library('parser');
		$this->load->helper('form');				$this->load->library('session');
		$this->load->helper(array('form', 'url'));
		$this->load->helper('language');
		$this->load->helper('html');
		$this->load->library('encrypt');
		$this->load->helper('url');
		$this->load->library('image_lib');
		$this->load->library('session');
		$this->load->library('zip');
		$this->load->library('unzip');
	}
	
	public function index()
	{
		$this->load->library('session');
		$this->load->library('parser');		
		$this->load->helper('language');
		$this->load->helper('form');
		$this->load->helper(array('form', 'url'));
		$this->load->helper('url');
		$this->load->helper('xml'); 
		$data = array();		
		$this->load->view('template/header',$data);
		$this->load->view('template/adventive',$data);
		$this->load->view('template/search',$data);
		$this->load->view('template/potsnews',$data);
		
		$this->load->model('news_model');
		$data['cateshow']=$this->news_model->cateshow(0);
		$data['catehide']=$this->news_model->catehide(0);
		$data['banner']=$this->news_model->banner();
		$data['newhot']=$this->news_model->newhot();
		$this->load->view('template/menuhome',$data);
		$this->load->view('template/homecontentleft',$data);
		$data['producthot']=$this->news_model->producthot();		$this->load->view('fronend/login',$data);		$listcate=$this->news_model->ListCateHome();		foreach($listcate as $row)
		{			$data['cateid']=$row->cateid;
			$data['catename']=$row->catename;
			$data['productshow']=$this->news_model->product($row->cateid,'',0,5,'');
			$data['producthide']=$this->news_model->product($row->cateid,'',0,5,"price asc");			//$this->load->view('template/homecontentleftcate2',$data);		}		$this->load->view('template/closediv');
		$data['newsshowtable']=$this->news_model->roomhot(1);
		$data['newshidetable']=$this->news_model->roomhot(0);
		$this->load->view('template/homecontentmenuright',$data);	
		$this->load->view('template/closediv');	
		$this->parser->parse('template/footer', $data,false);
	}
	
	function auth()	{		if (isset($_REQUEST['submit'])) {
			$name = $this->input->post('username');
			$pass = $this->input->post('userpass'); 
			$this->load->model('customer_model');
			$result = $this->customer_model->get_last_one_entries($name,$pass);
			if($result <> 0){
				$_SESSION['custkey'] =  $result; 
				$_SESSION['custname'] = $name;
				$_SESSION['datelog'] = date("Y-m-d H:i:s"); 
				$sessionArray = array('logged_in' => TRUE); 
				$_SESSION['logged_in'] = TRUE;								$newdata = array(                   'custkey'  => $result,                   'email'     => $name,                   'logged_in' => TRUE              	 );
				$this->session->set_userdata($sessionArray);				
				redirect('main');			}else {
				redirect('login');
			}
		}
	}
	function register(){
		if (isset($_REQUEST['submit'])) {
			$name = $this->input->post('username');
			$pass = $this->input->post('userpass'); 
			$this->load->model('customer_model');
			$result = $this->customer_model->get_last_one_entries($name,$pass);
			if($result <> 0){
				$_SESSION['custkey'] =  $result; 
				$_SESSION['custname'] = $name;
				$_SESSION['datelog'] = date("Y-m-d H:i:s"); 
				$sessionArray = array('logged_in' => TRUE); 
				$_SESSION['logged_in'] = TRUE;
				$this->session->set_userdata($sessionArray);
				redirect('home');
			}else {
				redirect('login');
			}
		}
	}		function logout()	{		$this->load->model('order_model');		$this->order_model->deleteusercart($_SESSION['custkey']);		$this->session->unset_userdata('custkey');		$this->session->unset_userdata('custname');		$this->session->unset_userdata('logged_in');		$this->session->unset_userdata('datelog');				$this->load->model('order_model');		$this->order_model->deleteusercart($_SESSION['custkey']);		session_destroy();		redirect('main');	}
	
}
